# 设置项目所需的cmake的最低版本
cmake_minimum_required(VERSION 3.5)

project(KpExt LANGUAGES CXX VERSION 0.1)

# 设置c++11标准
set(CMAKE_CXX_STANDARD 11)
# CMAKE_CXX_STANDARD设置的标准版本是否强制要求
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 阻止msvc unicode警告
add_compile_options("$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,18.99>>:/wd4819;/UTF-8>")

#  编译信息
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # 以json文件保存编译命令行, 生成的compile_commands.json 在构建目录，仅makefile和ninja构建器可用
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "" FORCE)  # 强制显示makefile信息


#########################  公共的库 #################################
# vulkan sdk
include(vulkan.cmake)  # 子目录内是可以访问的

# fmt库
include(fmtlib.cmake)

# spdlog库
#set(<variable> <value>... CACHE <type> <docstring> [FORCE])
set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "" FORCE) # 强制spdlog使用外部库
set(SPDLOG_BUILD_SHARED OFF CACHE BOOL "" FORCE) # 强制禁止spdlog构建成共享库
include(spdlog.cmake)
#target_include_directories(spdlog PUBLIC fmt)
#target_link_libraries(spdlog INTERFACE fmt)
#target_link_directories(spdlog INTERFACE fmt)

# nlohmann-json 库
include(nlohmann-json.cmake)

# googletest 库
include(googletest.cmake)

#######################################################################

if(CMAKE_SYSTEM_NAME MATCHES "Windows")  # 判断平台
    set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/build")
else()

endif()

#########################  要与ALL一起生成的目标 #################################

# gen_spirv_src可执行文件
add_subdirectory(gen_spirv_src)

# kp_ext静态库
add_subdirectory(kp_ext)

option(KPEXT_DEV_BASE_TEST "kpext library develop base test" ON)

if(KPEXT_DEV_BASE_TEST)

    # kp_ext开发时基本测试exe
    add_executable(kp_ext_tst
        kp_ext/main.cpp
        kp_ext/spdlog_custom.cpp
        kp_ext/KpExtGP.cpp
        )

    target_link_libraries(kp_ext_tst PUBLIC kp_ext_st)
    target_include_directories(kp_ext_tst PRIVATE kp_ext_st)
    target_link_directories(kp_ext_tst PRIVATE kp_ext_st)

    target_compile_definitions(kp_ext_tst PRIVATE KPEXT_DEV_MAIN KPEXT_BARE_SRC)

endif()

option(KPEXT_BUILD_GTEST "kpext library develop googletest full test" OFF)

if(KPEXT_BUILD_GTEST)
    # kp_ext 使用googletest多个测试套件进行测试
    add_subdirectory(test)
endif()

##################################################################
